{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Robodyno Motor API"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 1.电机状态设置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 初始化电机对象"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Motor(can, id_=0x10, type_=None)`\n",
    "\n",
    "参数：\n",
    "- `can` : can总线接口\n",
    "- `id_` : 电机ID,默认0x10（ 范围从 0x01 到 0x3F ）\n",
    "- `type_` : 电机的类型，默认自动识别\n",
    "    - ROBODYNO_PRO_01B\n",
    "    - ROBODYNO_PRO_01A\n",
    "    - ROBODYNO_PRO_02B\n",
    "    - ROBODYNO_PRO_02A\n",
    "    - ROBODYNO_PRO_03B\n",
    "    - ROBODYNO_PRO_03A\n",
    "    - ROBODYNO_PRO_04A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from robodyno.components import Motor\n",
    "from robodyno.interfaces import CanBus\n",
    "can = CanBus()\n",
    "motor = Motor(can, 0x10)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 电机使能"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`enable()`\n",
    "\n",
    "- 使能后，可以控制电机。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.enable()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 电机失能"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`disable()`\n",
    "\n",
    "- 这是上电后的默认状态。\n",
    "- 失能后，电机停止工作，转矩松动。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.disable()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 电机解锁"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`unlock()`\n",
    "- 此命令仅适用于带刹车的电机。解锁后，电机可自由旋转。\n",
    "- 如果电机不支持刹车,将会提示`NotImplementedError`错误"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.unlock()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 初始化当前位置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`init_pos(initial_pos = 0)`\n",
    "\n",
    "- 将电机的当前位置设置为初始位置。\n",
    "\n",
    "参数:\n",
    "\n",
    "- `initial_pos`: 当前初始位置(rad)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.init_pos(0)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "### 初始化绝对位置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`init_abs_pos(initial_pos = 0)`\n",
    "\n",
    "- 将电机当前的绝对位置设置为初始位置。\n",
    "- 若要断电后保存init位置需[保存参数设置](#保存设置)\n",
    "\n",
    "参数:\n",
    "- `initial_pos` : 当前初始绝对位置(rad)\n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.init_abs_pos(0)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 电机校准"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`calibrate()`\n",
    "\n",
    "- 如果需要，可以调用[保存参数设置](#保存设置)手动保存校准后的配置。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.calibrate()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置电机CAN_ID"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`config_can_bus(new_id, heartbeat = 1000, bitrate = 1000000)`\n",
    "\n",
    "参数 ：\n",
    "\n",
    "- `new_id` ：电机新CAN_ID (0x01~0x3F)\n",
    "- `heartbeat` : 心跳包发送周期 （ ms ）\n",
    "- `bitrate` : CAN总线通讯速率\n",
    "    - 1000000\n",
    "    - 500000\n",
    "    - 250000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.config_can_bus(new_id = 0x10)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 保存设置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`save()`\n",
    "- 如果电机处于`使能`状态，保存设置后电机将会处于`失能`状态"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.save()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 清除错误"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`clear_errors()`\n",
    "\n",
    "- 如果解决了原因，大多数错误都会自动清除。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.clear_errors()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 电机软急停"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`estop()`\n",
    "\n",
    "- 电机将立即失去扭矩，并报告一个停止错误(`ESTOP_REQUESTED`)。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.estop()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 电机重启"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`reboot()`\n",
    "\n",
    "- 电机重启后未保存的配置参数将会恢复为上一次保存的参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.reboot()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 恢复出厂设置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`reset()`\n",
    "\n",
    "- 此命令将电机重置为出厂设置。所有配置将丢失，id将重置为`0x10`。\n",
    "- 电机复位后必须重新[校准电机](#电机校准)才可再次使用。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.reset()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 2.电机模式设置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 进入直接位置模式"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`position_mode()`\n",
    "\n",
    "- 直接使用PID控制位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.position_mode()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 进入滤波位置模式"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`position_filter_mode(bandwidth)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `bandwidth`: 滤波带宽 / 控制频率(Hz)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.position_filter_mode(4)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 进入轨迹位置模式"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`position_track_mode(vel, acc, dec)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `vel`: 运动最高速度 ( rad/s )\n",
    "- `acc`: 运动加速度 ( rad/s^2 ), 必须为正值\n",
    "- `dec`: 运动减速度 ( rad/s^2 ), 必须为正值\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.position_track_mode(10,5,5)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 进入直接速度模式"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`velocity_mode()`\n",
    "\n",
    "- 直接使用PID控制速度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.velocity_mode()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 进入匀加减速速度模式"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`velocity_ramp_mode(ramp)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `ramp`: 运动加速度(rad/s^2), 必须为正值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.velocity_ramp_mode(1.414)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 进入力矩控制模式"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`torque_mode()`\n",
    "\n",
    "- 设置电机为力矩控制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.torque_mode()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {
    "jp-MarkdownHeadingCollapsed": true,
    "tags": []
   },
   "source": [
    "## 3.电机参数设置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置位置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`set_pos(pos, vel_ff=0, torque_ff=0)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `pos`: 目标位置(rad)\n",
    "- `vel_ff`: 速度前馈(rad/s), 默认：0。\n",
    "- `torque_ff`: 转矩前馈(Nm), 默认：0。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.set_pos(-1.57)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置绝对位置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`set_abs_pos(pos, vel_ff=0, torque_ff=0)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `pos`: 目标绝对位置(rad)\n",
    "- `vel_ff`: 速度前馈(rad/s), 默认：0。\n",
    "- `torque_ff`: 转矩前馈(Nm), 默认：0。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.set_abs_pos(0)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置速度"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`set_vel(vel, torque_ff = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `vel`: 目标速度(rad/s)\n",
    "- `torque_ff`: 转矩前馈(Nm), 默认：0。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.set_vel(0)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置力矩"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`set_torque(torque)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `torque`: 目标力矩(Nm)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.set_torque(0.0)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置电机PID参数"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`set_pid(pos_kp, vel_kp, vel_ki)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `pos_kp`: 位置环比例系数\n",
    "- `vel_kp`: 速度环比例系数\n",
    "- `vel_ki`: 速度环积分系数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.set_pid(100,0.02,0.1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置电机速度限制"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`set_vel_limit(vel_lim)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `vel_lim`: 输出端最大速度(rad/s), 必须为正值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.set_vel_limit(3.14)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 设置电机电流限制"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`set_current_limit(current_lim)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `current_lim` : 最大电流(A), 必须为正值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "motor.set_current_limit(10)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {
    "jp-MarkdownHeadingCollapsed": true,
    "tags": []
   },
   "source": [
    "## 4.读取电机参数"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机详细状态"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_state(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值 ：\n",
    "\n",
    "- 电机状态(MotorState)\n",
    "    - 1-空闲，8-使能\n",
    "- 电机错误(error)\n",
    "    - `error` : 错误码（1-电压不足，15-急停）\n",
    "    - `motor_err` : 电机相关错误码\n",
    "    - `encoder_err` : 编码器相关错误码\n",
    "    - `controller_err` : 控制器相关错误码\n",
    "- 电机控制模式(MotorControlMode)\n",
    "    - 直接位置模式 : (3,1)\n",
    "    - 滤波位置模式 : (3,3)\n",
    "    - 轨迹位置模式 : (3,5)\n",
    "    - 直接速度模式 : (2,1)\n",
    "    - 匀加减速速度模式 : (2,2)\n",
    "    - 力矩模式 : (1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<MotorState.ENABLED: 8>,\n",
       " {'error': <MotorError.NONE: 0>,\n",
       "  'motor_err': <MotorMotorError.NONE: 0>,\n",
       "  'encoder_err': <MotorEncoderError.NONE: 0>,\n",
       "  'controller_err': <MotorControllerError.NONE: 0>},\n",
       " <MotorControlMode.VELOCITY_RAMP_MODE: (2, 2)>)"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_state(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取总线电压"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_voltage(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值 ：\n",
    "\n",
    "- 总线电压值 ( V ) ，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12.079320907592773"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_voltage(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机温度"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_temperature(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 电机温度 ( °C ) ，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "47.80584716796875"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_temperature(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机控制模式"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_mode(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "返回值：\n",
    "\n",
    " - 控制模式(MotorControlMode)，控制参数字典(params)\n",
    "    - 直接位置模式 : (3,1)\n",
    "    - 滤波位置模式 : (3,3)\n",
    "        - `bandwidth` : 滤波带宽 / 控制频率(Hz)\n",
    "    - 轨迹位置模式 : (3,5)\n",
    "        - `vel`,`acc`,`dec` :  最高速度(rad/s), 加速度(rad/s^2),减速度(rad/s^2)\n",
    "    - 直接速度模式 : (2,1)\n",
    "    - 匀加减速速度模式 : (2,2)\n",
    "        - `ramp` : 加速度(rad/s^2)\n",
    "    - 力矩模式 : (1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(<MotorControlMode.VELOCITY_RAMP_MODE: (2, 2)>, {'ramp': 1.4140000393237941})"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_mode(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机参数反馈"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_feedback(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值 ：\n",
    "\n",
    "- 电机参数(位置rad, 速度rad/s, 力矩Nm)，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-8.691222907436727e-05, 0.0018390337854765357, -0.2378387451171875)"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_feedback(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机位置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_pos(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 位置(rad)，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-9.6181278024604e-05"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_pos(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机绝对位置"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_abs_pos(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 绝对位置(rad)，断电不丢失，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-1.5708973756003486"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_abs_pos(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机速度"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_vel(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 速度(rad/s)，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.005517101356429607"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_vel(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机力矩"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_torque(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 力矩(Nm)，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.07431411743164062"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_torque(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机PID参数"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_pid(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 电机PID\n",
    "    - `pos_kp` : 位置环P\n",
    "    - `vel_kp` : 速度环P\n",
    "    - `vel_ki` : 速度环I"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100.0, 0.0200042724609375, 0.0999755859375)"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_pid(1)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机速度限制"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_vel_limit(timeout = 0)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 输出端最大速度(rad/s)，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.711986642890533"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_vel_limit()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机电流限制"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_current_limit(timeout = 0)`\n",
    "\n",
    "参数:\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值：\n",
    "\n",
    "- 最大电流(A)，超时则不返回"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "13.0"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_current_limit()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 读取电机版本"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`get_version(timeout = 0)`\n",
    "\n",
    "参数：\n",
    "\n",
    "- `timeout` : 请求超时时间(s)，0代表无超时时间\n",
    "\n",
    "返回值 ：\n",
    "\n",
    "- API版本dict\n",
    "    - `main_version` : 主版本号\n",
    "    - `sub_version` : 副版本号\n",
    "    - `data` : 电机减速比\n",
    "    - `type` : 设备类型\n",
    "      - ROBODYNO_PRO_01B\n",
    "      - ROBODYNO_PRO_01A\n",
    "      - ROBODYNO_PRO_02B\n",
    "      - ROBODYNO_PRO_02A\n",
    "      - ROBODYNO_PRO_03B\n",
    "      - ROBODYNO_PRO_03A\n",
    "      - ROBODYNO_PRO_04A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'main_version': 2,\n",
       " 'sub_version': 0,\n",
       " 'data': -15.203125,\n",
       " 'type': <Model.ROBODYNO_PRO_02A: 3>}"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "motor.get_version(1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
